<!DOCTYPE html>
<html>
<head>
    <title>添加角色</title>
    <#include "/common/import.ftl" >
    <script>
        var pluginsSwitch = "${pluginsSwitch!''}";
        var itemOrgId = "${item.delStatus!''}";
        var orgId = "${orgId!''}";
        orgId = itemOrgId == "" ? orgId : itemOrgId;
        $(function () {
            $('#inputForm').form({
                onSubmit: function () {
                    if ("1" == pluginsSwitch && "1" != "${sysUser!''}") {
                        var orgIdjs = $('#orgId').combobox('getValue');
                        if (orgIdjs == "") {
                            $.messager.alert('提示', '请选择所属机构', 'info');
                            return false;
                        }
                    }
                    return $(this).form('validate');
                },
                success: function (data) {
                    var result = jQuery.parseJSON(data);
                    if (result.flag == 'T') {
                        $.messager.alert('提交结果', result.msg, 'info', function () {
                            parent.closeAdd();
                        });
                        parent.reload();
                    } else {
                        $.messager.alert('提交结果', result.msg, 'error', function () {
                            parent.closeAdd();
                        });
                        parent.reload();
                    }
                }
            });

            if ("${item.roleId!''}" != null && "${item.roleId!''}" != "") {
                $("#roleEname").attr("readonly", true);
            }
        });

    </script>

<body>

<div id="tip"></div>
<form id="inputForm" name="inputForm" method="post" action="${ctx }/uct/role/save.action">
    <table class="datagrid-body">
        <input type="hidden" name="formToken" id="formToken" value="${formToken!''}">
        <input type="hidden" name="roleId" id="roleId" value="${item.roleId!''}"/>
        <input type="hidden" name="orgParam" id="orgParam" value="${orgParam!''}"/>
        <input type="hidden" name="delStatus" id="delStatus" value="${item.delStatus!''}"/>
<#if '1'== pluginsSwitch>
            <tr class="Deprecated">
                <td class="datagrid-header">所属机构</td>
                <td>
                    <select id="orgId" name="orgId" style="width:184px;"></select>
                </td>
            </tr>
</#if>
        <tr>
            <td class="datagrid-header">角色名称<span style="color:red;">*</span></td>
            <td>
                <input name="roleCname" id="roleCname" value="${item.roleCname!''}"
                       class="easyui-validatebox"
                       data-options="required:true,validType:'length[2,30]'" size="30"
                       missingMessage="请输入角色名称" invalidMessage="应为2~30个字"/>
            </td>
        </tr>
        <tr>
            <td class="datagrid-header">角色标识<span style="color:red;">*</span></td>
            <td>
                <input id="roleEname" name="roleEname" value="${item.roleEname!''}"
                       class="easyui-validatebox" data-options="required:true,validType:'english'"
                       size="30"
                       missingMessage="角色标识，用字母组合"/>
            </td>
        </tr>
<#if '1'== pluginsSwitch>
    <#if item.roleId??><#else>
            <tr>
                <td class="datagrid-header">同步所有子机构</td>
                <td>
                    <input type="radio" name="synchSub" value="1"/>是
                    <input type="radio" name="synchSub" value="0" checked="checked"/>否
                </td>
            </tr>
    </#if>
</#if>

        <tr>
            <td class="datagrid-header"></td>
            <td>
                <input type="submit" value="提交"/>
            </td>
        </tr>
    </table>

</form>

<script type="text/javascript">

    function initOrg() {
        //初始化组织
        var url = "${ctx}/uct/org/org!initOrg.action";
        if ("1" == pluginsSwitch && "1" != "${sysUser!''}") {
            url = url + "?orgId=" + orgId;
        }
        $('#orgId').combobox({
            url: url,
            valueField: 'orgId',
            textField: 'orgCname'
        });
    }

    $(function () {
        if ("1" == pluginsSwitch) {
            initOrg();
            if ($("#roleId").val().length > 0) {
                $('#orgId').combobox('setValue', orgId);
                if ("1" != "${sysUser!''}") {
                    $('#orgId').combobox('disable');
                    document.getElementById("orgId").disabled = true;
                }
            } else {
                $('#orgId').combobox('setValue', orgId);
                if ("1" != "${sysUser!''}") {
                    $('#orgId').combobox('disable');
                    document.getElementById("orgId").disabled = true;
                }
            }
        }
    });

</script>
</body>
</html>
